'use strict';

/*
 * 主框架控制器，主要做一些配置化工作
 * 
 * @author yangw
 * @since 1.0.0
 */
app.controller('MainController', function($scope, $localStorage, $window) {
		/*add 'ie' classes to html*/ 
	    var isIE = !!navigator.userAgent.match(/MSIE/i);
	    isIE && angular.element($window.document.body).addClass('ie');
	    isSmartDevice( $window ) && angular.element($window.document.body).addClass('smart');
	    
	    $scope.app = {
		     name: 'Sweeter',
		     version: appversion,
		     color: { 
			       primary: '#7266ba',
			       info:    '#23b7e5',
			       success: '#27c24c',
			       warning: '#fad733',
			       danger:  '#f05050',
			       light:   '#e8eff0',
			       dark:    '#3a3f51',
			       black:   '#1c2b36'
		     },
		     settings: {
			       themeID: 1,
			       navbarHeaderColor: 'bg-black',
			       navbarCollapseColor: 'bg-white-only',
			       asideColor: 'bg-black',
			       headerFixed: true,
			       asideFixed: false,
			       asideFolded: false,
			       asideDock: false,
			       container: true
		    }
	    }
	
	    /*利用localStorage(一种html5提供的webstorage)对上面的配置做前端持久化，数据永不过期。*/ 
	    if (angular.isDefined($localStorage.settings)) {
	    	$scope.app.settings = $localStorage.settings;
	    } else {
	    	$localStorage.settings = $scope.app.settings;
	    }
	    
	    /*监听app.settings的变化，做出响应*/
	    $scope.$watch('app.settings', 
	        function(){
		         if( $scope.app.settings.asideDock  &&  $scope.app.settings.asideFixed ){
		           $scope.app.settings.headerFixed = true;
		         }
		         $localStorage.settings = $scope.app.settings;
	    	  }
	    , true);
	    
	    /*是否移动设备*/
	    function isSmartDevice( $window ){
	        // 此代码由  http://www.detectmobilebrowsers.com 提供
	        var ua = $window['navigator']['userAgent'] || $window['navigator']['vendor'] || $window['opera'];
	        // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
	        return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
	    }
	    
	}
);

/*
 * 全局搜索框控制器
 * 
 * @author yangw
 * @since 1.0.0
 */
app.controller('SearchController', ['$scope', '$http', function($scope, $http) {
    $scope.selected = undefined;
    $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
    $scope.getLocation = function(val) {
      return ['abc'];
    };
}]); 